package com.example.fengsam.aidong.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.fengsam.aidong.R;
import com.example.fengsam.aidong.adapter.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class ExerciseFragment extends Fragment {

    @BindView(R.id.tabLayout_exercise_select)
    TabLayout tabLayoutExerciseSelect;
    @BindView(R.id.vp_exercise_select)
    ViewPager vpExerciseSelect;
    Unbinder unbinder;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_exercise, container, false);

        unbinder = ButterKnife.bind(this, view);

        initViewPager();
        return view;
    }

    public void initViewPager() {
        List<Fragment> fragmentList = new ArrayList<>();
        List<String> titleList = new ArrayList<>();
        TrainingFragment trainingFragment=new TrainingFragment();
        RunningFragment runningFragment=new RunningFragment();
        fragmentList.add(runningFragment);
        fragmentList.add(trainingFragment);

        titleList.add("跑步");
        titleList.add("训练");

        tabLayoutExerciseSelect.setTabMode(TabLayout.MODE_FIXED);
        tabLayoutExerciseSelect.addTab(tabLayoutExerciseSelect.newTab().setText(titleList.get(0)));
        tabLayoutExerciseSelect.addTab(tabLayoutExerciseSelect.newTab().setText(titleList.get(1)));

        ViewPagerAdapter adapter=new ViewPagerAdapter(getActivity().getSupportFragmentManager(),fragmentList,titleList);
        vpExerciseSelect.setAdapter(adapter);
        tabLayoutExerciseSelect.setupWithViewPager(vpExerciseSelect);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
